<template>
	<view>
		<uni-list v-for="(item, index) in array" :index="index" :key="index">
			<uni-list-chat :title="item.name" avatar="https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png"
				:note="'满载容量:'+item.px+' * '+item.py+' * '+item.pz" :time="item.create"></uni-list-chat>
		</uni-list>
		<!-- 弹窗-创建数据记录 -->
		<uni-popup ref="showHouse" type="dialog">
			<uni-popup-dialog ref="inputClose" mode="input" title="创建新的仓库" value="对话框预置提示内容!" placeholder="请输入仓库名称"
				@confirm="submitForm"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				sConf: getApp().globalData,
				avatar: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png',
				count: 0,
				page: 1,
				array: []
			}
		},
		onReady() {
			if (!this.sConf.pos) {
				uni.navigateBack();
			} else {
				// 初始化表单数据
				// this.formData.pid = this.sConf.pos.id;
				this.queryData();
			}
		},
		onNavigationBarButtonTap(e) {
			console.log(e);
			if (e.text == "\ue468") {
				this.addNewWare();
			}
			if (e.type == 'close') {
				uni.navigateBack();
			}
		},
		methods: {
			fullContent(e) {
				var name = "";
				for (var str in e) {
					name += e[str];
				}
				return name;
			},
			addNewWare() {
				console.log("创建新的库房");
				this.$refs.showHouse.open();
			},
			submitForm(e) {
				console.log(e);
			},
			queryData() {
				var that = this;
				const requestTask = uni.request({
					url: that.sConf.host + '/ware/room/',
					method: 'GET',
					header: {
						'content-type': 'application/json',
						'authorization': that.sConf.token
					},
					data: {
						pid: that.sConf.pos?.id,
						page: that.page
					},
					success: function(res) {
						console.log(res.data);
						if (res.data.rescode == 200) {
							that.count = res.data.count;
							// that.array = res.data.resmsg
							// that.array.push(res.data.resmsg);
							let tarray = that.array
							res.data.resmsg.forEach(item => tarray.push(item));
							that.array = new Set(tarray);
						} else {
							uni.showToast({
								title: res.data.resmsg,
								icon: 'error',
								duration: 3000
							});
						}
					}
				});
			}
		}
	}
</script>

<style>

</style>